﻿using SenGe.Domain;

namespace SenGe.Infrastructure
{
    /// <summary>
    /// 基础仓储接口
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IBaseRepository<T> where T : BaseLongIdEntity
    {
        /// <summary>
        /// 检查数据库是否链接正确
        /// </summary>
        /// <returns></returns>
        Task<bool> CheckDb();
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="entity">数据模型</param>
        /// <returns></returns>
        bool Insert(T entity);
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="entity">数据模型</param>
        /// <returns></returns>
        Task<bool> InsertAsync(T entity);
        /// <summary>
        /// 插入数据列表
        /// </summary>
        /// <param name="entities">数据模型列表</param>
        /// <returns></returns>
        bool InsertList(List<T> entities);
        /// <summary>
        /// 插入数据列表
        /// </summary>
        /// <param name="entities">数据模型列表</param>
        /// <returns></returns>
        Task<bool> InsertListAsync(List<T> entities);
        /// <summary>
        /// 通过编号获取数据模型
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns></returns>
        T? GetById(object id);
        /// <summary>
        /// 通过编号获取数据模型
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns></returns>
        Task<T?> GetByIdAsync(object id);
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <returns></returns>
        PagedList<T> GetPagedList(int pageIndex = 1, int pageSize = 20);
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <returns></returns>
        Task<PagedList<T>> GetPagedListAsync(int pageIndex = 1, int pageSize = 20);
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity">数据模型</param>
        /// <returns></returns>
        bool Update(T entity);
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity">数据模型</param>
        /// <returns></returns>
        Task<bool> UpdateAsync(T entity);
        /// <summary>
        /// 删除指定编号数据模型
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns></returns>
        bool Delete(object id);
        /// <summary>
        /// 删除指定编号数据模型
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns></returns>
        Task<bool> DeleteAsync(object id);
    }
}
